Prev Next |
To be able to retrieve data, the database must be associated with one or more data providers. A data provider is a vendor specific implementation of a class that reads and writes data to a persistent medium. Examples of these include SQL Server, Oracle and Firebird.
The following definition will associate the 'myDB' database with an SQL Server specific data provider.
<database id="myDB" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
<param desc="name">$(id)</param>
<dataProviders hint="list:AddDataProvider">
<dataProvider type="Sitecore.Data.DataProviders.SqlServerDataProvider, Sitecore.SqlServer">
<param ref="connections/$(id)"/>
</dataProvider>
</dataProviders>
</database>
Usually the actual data provider configuration is kept in the <dataProviders> main section which is then referenced in the database definition. For example:
<database id="myDB" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
<param desc="name">$(id)</param>
<dataProviders hint="list:AddDataProvider">
<dataProvider ref="dataProviders/sqlserver" param1="$(id)"/>
</dataProviders>
</database>
The definition of the referenced data provider is:
<!-- DATA PROVIDERS -->
<dataProviders>
<sqlserver type="Sitecore.Data.DataProviders.SqlServerDataProvider, Sitecore.SqlServer">
<param ref="connections/$(1)"/>
</sqlserver>
...
</dataProviders>
The syntax '$(1)' refers the the 'param1' attribute in the reference. In turn, the '$(id)' in the 'param1' attribute refers to the 'id' attribute on the <database> element. The end result is that the value 'connections/$(1)' will be expanded to 'connections/myDB'.
The possible sub-elements of the <dataProvider> element depend on the type of data provider. For instance, the TemplateFileResolver supports a boolean property called AbortChain. To modify this value, you could write the following in web.config:
<!-- DATA PROVIDERS -->
<dataProviders>
<templatefile type="Sitecore.Data.DataProviders.TemplateFileResolver, Sitecore.Kernel">
<param desc="template file">$(1)</param>
<abortChain>true</abortChain>
</templatefile>
...
</dataProviders>
A chain is a string of data providers that serve a given database. When chaining data providers, it is often useful to enable and disable specific methods and method groups. The <dataProvider> tag accepts one or more <enable> or <disable> child tags. These can be used for turning specific methods on or off.
The tags support the wildcard character ('*'), which can be seen as a special method name that applies to all methods.
Example 1 - Disable all methods except GetItem and GetChildren:
<dataProvider ...>
<disable>*</disable>
<enable>GetItem</enable>
<enable>GetChildren</enable>
</dataProvider>
Example 2 - Disable the single method ChangeTemplate:
<dataProvider ...>
<disable>ChangeTemplate</disable>
</dataProvider>
To make working with groups of methods easier, a list of method groups have been added to the dataProviders/methodGroups section of web.config. These can be altered to suit specific cases. You may create new groups as desired.
The tags used when working with groups are <enableGroup> and <disableGroup>.
Example 3 - Disable all methods related to publishing:
<dataProvider ...>
<disableGroup>publishing</disableGroup>
</dataProvider>
Example 4 - Enable only methods related to reading items:
<dataProvider ...>
<disable>*</disable>
<enableGroup>read</enableGroup>
</dataProvider>
Prev Next